<script type="text/ecmascript-6">

  import Navbar from '../../components/base/navbar.vue';
  export default {
    name:"chub_comments",
    components: {
      Navbar
    },
    data() {
      return {
        page: 1,
        hasMore: true,
        id: this.$route.params.id,
        heights:"100%",
        total_number:0
      }
    },
    methods: {
      jump(page) {
        this.$router.push({ name: page });
      },
      done(){
        this.$nextTick(() => {
          this.$refs.pulldown.onLoadOff();
        })
      },
      refresh() {
        this.$store.dispatch('queryChutCommentsList',{id:this.id,method:'down'});
      },
      loadMore() {
          if(!this.hasMore){
          return this.$refs.pulldown.onLoadUp();
          }
        this.page=this.page+1;
        this.$store.dispatch('queryChutCommentsList',{id:this.id,page:this.page,method:"up"});
//        this.queryChutCommentsList(this.id, page);
      },
      completePage(success,page,method){
        if (success) {
          this.hasMore = page.current_page < page.total_pages;
          this.total_number=page.total;
          console.log(this.hasMore);
//          this.page = page.current_page;
        }
         this.$emit("done");
//        this.$refs.pulldown.onLoadDown();
//        this.$refs.pulldown.onLoadUp();

      }
    },
    created(){
        EventBus.$on("complete-page",this.completePage);
        this.$on("done",this.done);
    },
    mounted() {
        this.$store.dispatch('queryChutCommentsList',{id:this.id});
//      this.$Loading();
//      this.queryChutCommentsList(this.id);
    },
    beforeDestroy(){
        EventBus.$off("complete-page");
    },
    computed:{
        chubComments:{
            get(){
                return this.$store.getters.getChutCommentsList
            }
        }
    }
  }
</script>
